package cn.edu.zafu.bigdata.x.zhouyuyan.work10;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class TPClient {
    public static void main(String[] args) {
        String hostname = "192.168.16.1";
        int port = 11234;

        try(Socket socket = new Socket(hostname, port);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))){
            System.out.println("已连接到服务端：" + hostname + "在端口：" + port);
            String userInput;
            while ((userInput = stdIn.readLine()) != null){
                out.println(userInput);
                System.out.println("服务端回复：" + in.readLine());
            }
        }catch (UnknownHostException e){
            System.err.println("无法找到主机：" + e.getMessage());
        }catch (IOException e){
            System.err.println("IO 错误：" + e.getMessage());
        }
    }
}
